﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoolERP_Entities;
using CoolERP_DAL;

namespace CoolERP_BLL
{
    public class ZL_CPBZXBLL : BaseBLL<ZL_CPBZX>
    {       
        public ZL_CPBZXBLL() { }

        public List<ZL_CPBZX> GetCPBZX(Dictionary<string, string> dc, string orderExpr, int? pageIndex, int pageSize, out int totalCount)
        {
            var predicate = PredicateExtensions.True<ZL_CPBZX>();
            if (dc != null && dc.Count > 0)
            {
                if (dc.ContainsKey("NotWPID") && !string.IsNullOrEmpty(dc["NotWPID"]))
                {
                    string[] ids = dc["NotWPID"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    predicate = predicate.AndEx(t => !ids.Contains(t.ID.ToString()));
                }
                if (dc.ContainsKey("cpxbh") && !string.IsNullOrEmpty(dc["cpxbh"]))
                    predicate = predicate.AndEx(t => t.CPXBH == dc["cpxbh"]);
                if (dc.ContainsKey("hxcbh") && !string.IsNullOrEmpty(dc["hxcbh"]))
                    predicate = predicate.AndEx(t => t.CPMCBH == dc["hxcbh"]);
                if (dc.ContainsKey("bh") && !string.IsNullOrEmpty(dc["bh"]))
                    predicate = predicate.AndEx(t => t.BH.Contains(dc["bh"]));
                if (dc.ContainsKey("mc") && !string.IsNullOrEmpty(dc["mc"]))
                    predicate = predicate.AndEx(t => t.MC.Contains(dc["mc"]));
                if (dc.ContainsKey("lx") && !string.IsNullOrEmpty(dc["lx"]))
                {
                    int keyVal = Convert.ToInt32(dc["lx"]);
                    predicate = predicate.AndEx(t => t.BZXLX == keyVal);
                }
            }
            
            return base.GetPagerList(predicate.Compile(), orderExpr, pageIndex, pageSize, out totalCount);
        }
    }
}
